package api

import (
	"gomain/app/service"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
)

type OrderApi struct{}

func (a *OrderApi) List(r *ghttp.Request) {
	page := r.Get("page", 1).Int()
	limit := r.Get("limit", 10).Int()

	orders, count, err := service.Order.List(page, limit)
	if err != nil {
		r.Response.WriteJson(g.Map{
			"code": 1,
			"msg":  err.Error(),
		})
		return
	}

	r.Response.WriteJson(g.Map{
		"code":  0,
		"msg":   "success",
		"data":  orders,
		"count": count,
	})
}
